package com.usian.controller;

import com.usian.SearchFeign;
import com.usian.pojo.SearchItem;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/frontend/searchItem")
public class SearchController {

    @Autowired
    private SearchFeign searchFeign;


    /**
     * 商品库导入  mysql-- es
     * @return
     */
    @RequestMapping("importAll")
    public Result importAll(){
        boolean bool = searchFeign.importAll();
        if(bool){
            return Result.ok("导入成功");
        }
        return Result.error("导入失败");
    }


    /**
     * 首页搜索
     *
     * @param q
     * @param page
     * @param pageSize
     * @return
     */
    @RequestMapping("list")
    public List<SearchItem> selectByQ(String q,
                                 @RequestParam(defaultValue = "1") Long page,
                                 @RequestParam(defaultValue = "20")Long pageSize){
        return searchFeign.selectByQ(q,page,pageSize);
    }

}
